package rach.grid.andgrid1;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;

public class AndroidReadFile {

	private Activity a;

	public AndroidReadFile(Activity a) {
		this.a = a;
	}

	public InputStream[] getDirectoryFiles() throws IOException {
		
			String[] files = a.getAssets().list("");
			if (files == null || files.length == 0) {
				throw new IOException("No files to read");
			}
			List<InputStream> list = new ArrayList<InputStream>();
			for (String file : files) {
				if (file.endsWith(".txt")) {
					InputStream is = a.getAssets().open(file);
					if (is == null) {
						throw new IOException("Could not get stream for " + file);
					}
					list.add(is);
				}
			}
			return list.toArray(new InputStream[list.size()]);
		
	}

}
